# 变量的作用域
def fun():
    a = 20
    return a


a = 10
print(a)
print(fun())


# 利用递归函数计算100的阶乘
def f(n):
    if n <= 1:
        return 1
    else:
        return n*f(n-1)


num = int(input("请输入一个正整数"))
s = f(num)
print(num, "的阶乘是:", s)


# 利用递归计算1~100加和
def sum(n):
    if n == 1:
        return 1
    else:
        return n+sum(n-1)


print("1~100相加的和为", sum(100))


# 计算斐波那契数列
def fibo(n):
    if n <= 2:
        return 1
    else:
        return fibo(n-1)+fibo(n-2)


print("斐波那契数列的第{}项为{}".format(7, fibo(7)))


# 匿名函数
sum = lambda a, b, c: a+b+c
print(sum(1, 2, 3))


# 编写lambda函数
fun = lambda m: m**2
print(fun(5))
